home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #9
/
Amiga Plus CD - 2004 - No. 09.iso
/
amigaplus
/
tools
/
dev_libs
/
feelin040718
/
demos
/
class1.c
< prev
next >
Wrap
C/C++ Source or Header
|
2004-08-03
|
4KB
|
165 lines
;/*
F_Create.rexx EXE Class1
QUIT
_________________________________________________________________________
Demosource on how to use a customclass in C.
Based on the MUI C example 'Class1.c'.
Written by LAVIALE Olivier <HaploLaMain@aol.com>
*/
#include <libraries/feelin.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/feelin.h>
struct FeelinBase *FeelinBase;
/*
Unlike MUI, Feelin doesn't use _kludges_ to access FC_Area local data.
This behaviour gives total independency between FC_Object (FC_Notify)
and FC_Area, but need some work around.
Most FC_Area macros access area data transparently, but they need the
field 'AreaData' to be defined in the 'LOD' variable :
local_area_data = LOD -> AreaData;
To easily access FC_Area data get the attribute FA_AreaData at object
creation time and save to pointer into the 'AreaData' of the
'LocalObjectData' structure. Then, you can use macros as usualy, but
omitting the "(Obj)" because they use directly the variable 'LOD' of
type LocalObjectData :
_minw
is expanded to
LOD -> AreaData -> MinMax.MinW
*/
struct LocalObjectData
{
FAreaData *AreaData;
};
///mNew
F_METHOD(ULONG,mNew)
{
struct LocalObjectData *LOD = F_LOD(Class,Obj);
LOD -> AreaData = (FAreaData *) F_Get(Obj,FA_AreaData);
return F_SUPERDO();
}
//+
///mAskMinMax
F_METHOD(ULONG,mAskMinMax)
{
struct LocalObjectData *LOD = F_LOD(Class,Obj);
/*
FM_AskMinMax will be called before the window is opened and before layout
takes place. We need to tell Feelin the minimum and maximum size of our
object.
*/
_minw += 100 ; _maxw = 500;
_minh += 40 ; _maxh = 300;
return F_SUPERDO();
}
//+
///mDraw
F_METHODM(void,mDraw,FS_Draw)
{
struct LocalObjectData *LOD = F_LOD(Class,Obj);
struct RastPort *rp = _rp;
UWORD x1 = _mx, x2 = _mx2,
y1 = _my, y2 = _my2;
ULONG i,c=FV_Pen_Shine;
/*
let our superclass draw itself first, FC_Area would e.g. draw the frame
and clear the whole region. What it does exactly depends on flags.
*/
F_SUPERDO();
/* Ok, everything ready to render... */
for (i = x1 ; i <= x2 ; i += 5)
{
_FPen(c);
_Move(x1,y2); _Draw(i,y1);
_Move(x2,y2); _Draw(i,y1);
if (++c == FV_Pen_Highlight) c = FV_Pen_Shine;
}
}
//+
/// Main
void main()
{
FObject app,win;
struct FeelinClass *cc;
if (FeelinBase = (APTR) OpenLibrary("feelin.library",FV_VERSION))
{
static struct FeelinMethodEntry Handlers[] =
{
(FMethod) mNew, NULL, FM_New,
(FMethod) mAskMinMax, NULL, FM_AskMinMax,
(FMethod) mDraw, NULL, FM_Draw,
NULL
};
if (cc = F_CreateClass(FA_Class_LODSize, sizeof (struct LocalObjectData),
FA_Class_Super, FC_Area,
FA_Class_MethodsTable, Handlers,
TAG_DONE))
{
app = AppObject,
FA_Application_Title, "Class1",
FA_Application_Version, "$VER: Class1 1.04 (2004/03/13)",
FA_Application_Copyright, "©2002, Olivier LAVIALE",
FA_Application_Author, "Olivier LAVIALE (HaploLaMain@aol.com)",
FA_Application_Description, "Demonstrate the use of custom classes.",
FA_Application_Base, "CLASS1",
Child, win = WindowObject,
FA_ID, MAKE_ID('M','A','I','N'),
FA_Window_Title, "A Simple Custom Class",
FA_Window_Open, TRUE,
Child, F_NewObj(cc -> Name, FA_Frame,"0:28.04040404", TextBack, End,
End,
End;
if (app)
{
F_Do(win,FM_Notify,FA_Window_CloseRequest,TRUE, app,FM_Application_Shutdown,0);
F_Do(app,FM_Application_Run);
F_DisposeObj(app);
}
F_DeleteClass(cc);
}
else Printf("Unable to create custom class\n");
CloseLibrary(FeelinBase);
}
else Printf("Unable to open feelin.library\n");
}
//+